# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>

pkgname=haskell-primitive
pkgver=0.7.4.0
pkgrel=67
pkgdesc="Wrappers for primitive operations"
url="https://hackage.haskell.org/package/primitive"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs')
makedepends=('ghc' 'uusi')
checkdepends=('haskell-base-orphans' 'haskell-quickcheck' 'haskell-quickcheck-classes-base'
              'haskell-tasty' 'haskell-tasty-quickcheck' 'haskell-tagged'
              'haskell-transformers-compat')
source=("https://hackage.haskell.org/packages/archive/primitive/${pkgver}/primitive-${pkgver}.tar.gz")
sha512sums=('5c01ea4fc509ccb8f00b7d282948e8fa120d2ee3abd09c4efa473496ce6a716e26a95994a30bb8e18754a6226cbcaf102264e263e517d4ff2cea2d67216eb6c7')

prepare() {
  cd primitive-$pkgver
  gen-setup
}

build() {
  cd primitive-$pkgver

  if (( CHECKFUNC )); then
    _opts=('--enable-tests')
  else
    _opts=('--disable-tests')
  fi

  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
      --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname "${_opts[@]}" \
      --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
  runhaskell Setup build $MAKEFLAGS
  runhaskell Setup register --gen-script
  runhaskell Setup unregister --gen-script
  sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
  sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
  cd primitive-$pkgver
  runhaskell Setup test --show-details=direct
}

package() {
  cd primitive-$pkgver
  install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
  install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
  runhaskell Setup copy --destdir="$pkgdir"
  install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/${pkgname}/LICENSE
  rm -f "$pkgdir"/usr/share/doc/${pkgname}/LICENSE
}
